using UnityEngine;

namespace ProceduralPrimitivesUtil
{
	public class Prism : PPBase
	{
		[Header("Basic parameters")]
		public float width = 1f;

		public float length = 1f;

		public float height = 1f;

		public float offset;

		[Header("Segments")]
		public int sideSegs = 2;

		public int heightSegs = 2;

		[Header("Mapping Coordinates")]
		public bool generateMappingCoords = true;

		public bool realWorldMapSize;

		public Vector2 UVOffset = new Vector2(0f, 0f);

		public Vector2 UVTiling = new Vector2(1f, 1f);

		[Header("Others")]
		public bool flipNormals;

		protected override void CreateMesh()
		{
			m_mesh.name = "Prism";
			width = Mathf.Clamp(width, 1E-05f, 10000f);
			length = Mathf.Clamp(length, 1E-05f, 10000f);
			height = Mathf.Clamp(height, 1E-05f, 10000f);
			offset = Mathf.Clamp(offset, -10000f, 10000f);
			sideSegs = Mathf.Clamp(sideSegs, 1, 100);
			heightSegs = Mathf.Clamp(heightSegs, 1, 100);
			float num = length * 0.5f;
			float num2 = width * 0.5f;
			float num3 = height * 0.5f;
			CreateTriangle(pivotOffset + m_rotation * new Vector3(0f, num3, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.right, width, length, offset, sideSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreateTriangle(pivotOffset + m_rotation * new Vector3(0f, 0f - num3, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.right, width, length, offset, sideSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
			Vector3 vector = new Vector3(0f - num2, 0f, 0f - num);
			Vector3 vector2 = new Vector3(offset, 0f, num);
			Vector3 vector3 = new Vector3(num2, 0f, 0f - num);
			Vector3 vector4 = vector - vector2;
			Vector3 vector5 = vector2 - vector3;
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f, 0f - num), m_rotation * Vector3.up, m_rotation * Vector3.right, width, height, sideSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * (vector + vector2) * 0.5f, m_rotation * Vector3.up, m_rotation * vector4.normalized, vector4.magnitude, height, sideSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * (vector2 + vector3) * 0.5f, m_rotation * Vector3.up, m_rotation * vector5.normalized, vector5.magnitude, height, sideSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
		}
	}
}
